﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BCCommon;
using System.Text;
using System.Net;
using Microsoft.AspNetCore.Mvc;
using BCDto.Trading.SaleGoods.SaleGoodsCategory;
using BCTMSRESTful.Configs;
using BCService.Utils;
using BCService.Trading.SaleGoods.SaleGoodsCategory;

namespace BCTMSRESTful.Controllers.Management.Trading.SaleGoods
{
    /// <summary>
    /// 销售商品分类
    /// </summary>
    [ApiExplorerSettings(GroupName = "AdminTrading")]
    [Route("api/v1/sim/[controller]")]
    public class SaleGoodsCategoryController : ManagementBaseController
    {
        private readonly ISaleGoodsCategoryService saleGoodsCategoryService;

        public SaleGoodsCategoryController(ISaleGoodsCategoryService saleGoodsCategoryService)
        {
            this.saleGoodsCategoryService = saleGoodsCategoryService;
        }

        #region 添加销售商品分类
        /// <summary>
        ///  添加销售商品分类
        /// </summary>
        /// <param name="requestDto">销售商品分类信息</param>
        /// <response code="201">添加销售商品分类成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPost]
        [Log("添加销售商品分类")]
        [ProducesResponseType(typeof(SaleGoodsCategoryDto), 201)]
        public IActionResult Post(
            [FromBody]SaleGoodsCategoryRequestDto requestDto)
        {
            var result = this.saleGoodsCategoryService.Add(requestDto);
            return StatusCode((int)HttpStatusCode.Created, result);
        }
        #endregion

        #region 修改销售商品分类
        /// <summary>
        ///  修改销售商品分类
        /// </summary>
        /// <param name="saleGoodsCategoryId">销售商品分类Id</param>
        /// <param name="requestDto">销售商品分类信息</param>
        /// <response code="200">修改销售商品分类成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPut("{sale_goods_category_id}")]
        [Log("修改销售商品分类")]
        [ProducesResponseType(typeof(SaleGoodsCategoryDto), 200)]
        public IActionResult Put([FromRoute(Name = "sale_goods_category_id")]long saleGoodsCategoryId, [FromBody]SaleGoodsCategoryRequestDto requestDto)
        {
            SaleGoodsCategoryPutDto putDto = requestDto.As<SaleGoodsCategoryPutDto>();
            putDto.SaleGoodsCategoryId = saleGoodsCategoryId;
            return StatusCode((int)HttpStatusCode.OK, this.saleGoodsCategoryService.Update(putDto));
        }
        #endregion

        #region 删除销售商品分类
        /// <summary>
        ///  删除销售商品分类
        /// </summary>
        /// <param name="saleGoodsCategoryId">销售商品分类Id</param>
        /// <response code="204">删除销售商品分类成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpDelete("{sale_goods_category_id}")]
        [Log("删除销售商品分类")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Delete([FromRoute(Name = "sale_goods_category_id")]long saleGoodsCategoryId)
        {
            this.saleGoodsCategoryService.Delete(saleGoodsCategoryId);
            return StatusCode((int)HttpStatusCode.NoContent);
        }
        #endregion

        #region 获取销售商品分类
        /// <summary>
        ///  获取销售商品分类
        /// </summary>
        /// <param name="saleGoodsCategoryId">销售商品分类Id</param>
        /// <response code="200">获取销售商品分类</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("{sale_goods_category_id}")]
        [ProducesResponseType(typeof(SaleGoodsCategoryDto), 200)]
        public IActionResult Get([FromRoute(Name = "sale_goods_category_id")]long saleGoodsCategoryId)
        {
            return StatusCode((int)HttpStatusCode.OK, this.saleGoodsCategoryService.Get(saleGoodsCategoryId));
        }
        #endregion

        #region 获取销售商品分类列表
        /// <summary>
        ///  获取销售商品分类列表
        /// </summary>
        /// <response code="200">获取销售商品分类列表</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(IEnumerable<SaleGoodsCategoryDto>), 200)]
        public IActionResult Get()
        {
            return StatusCode((int)HttpStatusCode.OK, this.saleGoodsCategoryService.GetList());
        }
        #endregion

        #region 获取销售商品分类（分页）
        /// <summary>
        ///  获取销售商品分类（分页）
        /// </summary>
        /// <param name="saleGoodsCategoryId">销售商品分类Id</param>
        /// <param name="enabled">是否启用</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="sortName">排序字段</param>
        /// <param name="ascending">升序</param>
        /// <param name="index">当前页码</param>
        /// <param name="size">当前页大小</param>
        /// <response code="200">获取销售商品分类（分页）</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<SaleGoodsCategoryDto>), 200)]
        public IActionResult Query(
            [FromQuery(Name = "sale_goods_category_id")]long? saleGoodsCategoryId,
            [FromQuery(Name = "enabled")]bool? enabled,
            [FromQuery(Name = "start")]DateTime? start,
            [FromQuery(Name = "end")]DateTime? end,
            [FromQuery(Name = "sort_name")]string sortName,
            [FromQuery(Name = "ascending")]bool? ascending,
            [FromQuery(Name = "index")]int index = 1,
            [FromQuery(Name = "size")]int size = 10)
        {
            return StatusCode((int)HttpStatusCode.OK, this.saleGoodsCategoryService.Query(saleGoodsCategoryId,enabled, start, end, sortName, ascending, index, size));
        }
        #endregion

        #region 启用/禁用销售商品分类
        /// <summary>
        ///  启用/禁用销售商品分类
        /// </summary>
        /// <param name="saleGoodsCategoryId">销售商品分类Id</param>
        /// <param name="enabled">是否启用</param>
        /// <response code="204">启用/禁用销售商品分类成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPut("[action]/{sale_goods_category_id}/{enabled}")]
        [Log("启用/禁用销售商品分类")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Enabled([FromRoute(Name = "sale_goods_category_id")]long saleGoodsCategoryId,
            [FromRoute(Name = "enabled")]bool enabled)
        {
            if (enabled)
            {
                this.saleGoodsCategoryService.Enabled(saleGoodsCategoryId);
                return StatusCode((int)HttpStatusCode.NoContent);
            }
            else
            {
                this.saleGoodsCategoryService.Disabled(saleGoodsCategoryId);
                return StatusCode((int)HttpStatusCode.NoContent);
            }
        }
        #endregion
    }
}

